<?php
/*
 * File AgendaTheorieTest.php for project Rijlesplanner.nl
 * Created on 11 dec 2007 at 00:00:57 by Ivar Pruijn
 */

require_once PEAR_DIR . '/PHPUnit/Framework.php';

require_once ("../modules/authentication.php");

class VekaTheorieTest extends PHPUnit_Framework_TestCase {
	private $config;
	private $template;
	private $wsclient;
	private $logger;
	private $auth;

	public function setUp() {
		$this->config = $_SESSION['config'];
		require_once PEAR_DIR . 'Log.php';
		$logger = & Log :: singleton('firebug', '', 'Rijlesplanner.nl', array (
			'buffering' => true,
			'timeFormat' => '%b %d %H:%M:%S'
		), PEAR_LOG_DEBUG);
		$this->logger = $logger;
		// templating
		$smarty = new Smarty_Rijlesplanner();
		$this->template = $smarty;
		$this->wsclient = new SoapClient($this->config['dashboard_wsdl'], array (
			'trace' => 1,
			'classmap' => array (
				'Leerling' => "Leerling"
			)
		));
		$auth = new Authentication();
		$auth->configure(array (
			"config" => $this->config,
			"logger" => $this->logger,
			"template" => $this->template,
			"wsclient" => $this->wsclient
		));
		$this->auth = $auth;

		$_POST['rijschool'] = 'dation';
		$_POST['email'] = 'test';
		$_POST['password'] = 'test';
	}

	public function testAgendaTheorie_Annuleer() {
		if ($this->auth->login()) {
			$sessionId = $_SESSION['SessionId'];
			$user = $_SESSION['user'];
			try {
				$result1 = $this->wsclient->WS_Leerling_GetCursussen(array (
					'RijschoolId' => $user->getRijschoolId(),
					'SessionId' => $sessionId,
					'LeerlingId' => $user->getId()
				));
				$cursusId = $result1->Cursussen[0]->Id;
				
				$theorieId = null;

				$result2 = $this->wsclient->WS_AgendaTheorie_Annuleer(array (
					'RijschoolId' => $user->getRijschoolId(),
					'SessionId' => $sessionId,
					'CursusId' => $cursusId,
					'TheorieId' => $theorieId
				));
				$this->logger->log($result2, PEAR_LOG_DEBUG);

			} catch (SoapFault $e) {
				$this->logger->log("SOAP Fault: (faultcode: {$e->faultcode} faultstring: {$e->faultstring})",PEAR_LOG_ERR);
				//$this->logger->log("WS Client: ".print_r($this->wsclient,true),PEAR_LOG_ERR);
			}
		} else {
			$this->logger->log("Could not log in",PEAR_LOG_ERR);
			//$this->logger->log("WS Client: ".print_r($this->wsclient,true),PEAR_LOG_ERR);
		}
	}

	public function testAgendaTheorie_Plan() {
		if ($this->auth->login()) {
			$sessionId = $_SESSION['SessionId'];
			$user = $_SESSION['user'];
			try {
				$result1 = $this->wsclient->WS_Leerling_GetCursussen(array (
					'RijschoolId' => $user->getRijschoolId(),
					'SessionId' => $sessionId,
					'LeerlingId' => $user->getId()
				));
				$cursusId = $result1->Cursussen[0]->Id;
				
				$theorieId = null;

				$result2 = $this->wsclient->WS_AgendaTheorie_Plan(array (
					'RijschoolId' => $user->getRijschoolId(),
					'SessionId' => $sessionId,
					'CursusId' => $cursusId,
					'TheorieId' => $theorieId
				));
				$this->logger->log($result2, PEAR_LOG_DEBUG);

			} catch (SoapFault $e) {
				$this->logger->log("SOAP Fault: (faultcode: {$e->faultcode} faultstring: {$e->faultstring})",PEAR_LOG_ERR);
				//$this->logger->log("WS Client: ".print_r($this->wsclient,true),PEAR_LOG_ERR);
			}
		} else {
			$this->logger->log("Could not log in",PEAR_LOG_ERR);
			//$this->logger->log("WS Client: ".print_r($this->wsclient,true),PEAR_LOG_ERR);
		}
	}

	public function testAgendaTheorie_Lijst() {
		if ($this->auth->login()) {
			$sessionId = $_SESSION['SessionId'];
			$user = $_SESSION['user'];
			try {
				$result1 = $this->wsclient->WS_Leerling_GetCursussen(array (
					'RijschoolId' => $user->getRijschoolId(),
					'SessionId' => $sessionId,
					'LeerlingId' => $user->getId()
				));
				$cursusId = $result1->Cursussen[0]->Id;

				$result2 = $this->wsclient->WS_AgendaTheorie_Lijst(array (
					'RijschoolId' => $user->getRijschoolId(),
					'SessionId' => $sessionId,
					'CursusId' => $cursusId
				));
				$this->logger->log($result2, PEAR_LOG_DEBUG);

			} catch (SoapFault $e) {
				$this->logger->log("SOAP Fault: (faultcode: {$e->faultcode} faultstring: {$e->faultstring})",PEAR_LOG_ERR);
				//$this->logger->log("WS Client: ".print_r($this->wsclient,true),PEAR_LOG_ERR);
			}
		} else {
			$this->logger->log("Could not log in",PEAR_LOG_ERR);
			//$this->logger->log("WS Client: ".print_r($this->wsclient,true),PEAR_LOG_ERR);
		}
	}

}	
?>
